#pragma once

#include <QObject>
#include <QThread>
#include <QMutex>
#include <QDebug>
#include "canthread.h"

class Worker : public QObject
{
	Q_OBJECT
public:
	static constexpr size_t limitQSize = 500;
	explicit Worker(QMutex& mainMutex, CANThread* canThread,
		QQueue <CANThread::CanData>& q0, QQueue <CANThread::CanData>& q1,
		QObject* parent = nullptr)
		: QObject(parent), m_mutex(mainMutex), canThread(canThread), q0(q0), q1(q1), bStop(false)
	{}
	inline void stop() { bStop = true; }

public slots:
	void doWork();

signals:
	void progressUpdate(int percent);
	void resultReady(int result);
	void complete();

private:
	QMutex& m_mutex;
	CANThread* canThread;
	QQueue <CANThread::CanData>& q0, & q1;
	bool bStop;
};